package com.sky.mapper;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderListVO;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {
    /**
     * 新建订单
     * */
    void add(Orders orders);
    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
    /**
     * 条件分页查询
     * */
    List<OrderListVO> getHistoryOrders(OrdersPageQueryDTO dto);
    @Select("select status from orders where id=#{id}")
    Integer getStatusById(Long id);
    /**
     * 统计各状态的订单数量
     * */
    OrderStatisticsVO statistics();
    /**
     * 获取付款超时订单
     * */
    @Select("select * from orders where status=#{status} and order_time<#{time}")
    List<Orders> getByStatusAndRederTime(Integer status, LocalDateTime time);
    /**
     * 统计每天的营业额
     * */
    Double sumByMap(Map map);

    Integer countByMap(Map map);

    @MapKey("name")
    List<Map> top(Map map);
}
